<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>双向绑定</title>
</head>

<body>
    <template id="sub-component">
        <div>
            <h2>子组件</h2>
            <p>{{title}}</p>
            子组件文本框：<input type="text" @input="$emit('update:title',$event.target.value)"/>
        </div>
    </template>
    <main id="app">
        <h2>父组件</h2>
        <p>{{title}}</p>
        父组件文本框：<input type="text" v-model="title"/>
        <sub-component :title.sync="title"></sub-component>
    </main>
</body>
<script src="../vue.min.js"></script>
<script>

    Vue.component("sub-component", {
        template: `#sub-component`,
        props: {
            title: {
                type: String
            }
        }
    })

    new Vue({
        el: "#app",
        data() {
            return {
                title: "标题"
            }
        }
    })
</script>

</html>